<template>
  <div id="app">
    <nav>
<!--      <router-link to="/">Home</router-link> |-->
<!--      <router-link to="/about">About</router-link>-->
        <el-container>
            <el-header>servlet + Mybatis + Maven + Vue + ElementUI</el-header>
            <el-container>
                <el-aside width="200px">
                    <el-menu
                            class="el-menu-vertical-demo"
                            background-color="#545c64"
                            text-color="#fff"
                            active-text-color="#ffd04b">
                        <span style="color:white;font:25px 楷体">BNZ-后台首页</span>
                        <br>

                    </el-menu>

                    <el-menu
                            default-active="2"
                            router
                            class="el-menu-vertical-demo"
                            background-color="#545c64"
                            text-color="#fff"
                            active-text-color="#ffd04b">
                        <el-submenu :index="menu.path" v-for="menu in menus":key="menu.path">
                            <template slot="title">
                                <i :class="menu.icon" style="color:deepskyblue"></i>
                                <span>{{menu.title}}</span>
                            </template>
                            <el-menu-item-group >
                                <el-menu-item :index="menu.path + child.path" v-for="child in menu.children" :key="child.path">
                                 <i :class="child.icon">{{child.title}}</i>
                                </el-menu-item>
                            </el-menu-item-group>

                        </el-submenu>

                    </el-menu>
                </el-aside>
                <el-container>


                    <el-main>
                        <!--1.卡片布局内容页面-->
                        <el-card class="box-card" shadow="hover">
                            <!--1.1 内部面包屑导航-->
                            <el-breadcrumb separator-class="el-icon-arrow-right">
                                <el-breadcrumb-item>首页</el-breadcrumb-item>
                                <el-breadcrumb-item :to="{ path: '/student'}">{{title1}}</el-breadcrumb-item>
                                <el-breadcrumb-item :to=" { path: '/student/list'} ">{{title2}}</el-breadcrumb-item>
                            </el-breadcrumb>

                            <!--1.2 显示子控件的内容-->
                            <router-view/>
                        </el-card>

                    </el-main>


                    <el-footer>Footer</el-footer>
                </el-container>
            </el-container>
        </el-container>
    </nav>
<!--    <router-view/>-->
  </div>
</template>
<script>
    import menus from "@/api/menus";
    export default {
        data(){
            return{
                menus,
                title1:"",
                title2:""
            }
        },
        created() {
            let path = this.$route.path;
            // console.log("path",path)
            this.init(path);
        },
        methods:{
            init(path){
                this.menus.forEach(menu=>{
                    menu.children.forEach(child => {
                        if(menu.path + child.path === path){
                            this.title1 = menu.title;
                            this.title2 = child.title;
                            console.log(this.title1)
                            console.log(this.title2)
                        }
                    })
                })
            }
        },
        watch:{
            "$route.path"(newV,oldV){
                this.init(newV)
            }
        }
    }
</script>

<style>
    *{
        padding: 0;
        margin: 0;
    }
    .el-menu-item{
        padding-left: 20px;

    }
    .el-header, .el-footer {
        background-color: rgb(84,92,100);
        color: white;
        text-align: center;
        line-height: 60px;
    }

    .el-aside {
        background-color: rgb(84,92,100);  /*#D3DCE6*/
        color: #333;
        text-align: center;
        /*line-height: 200px;*/
        height: 1600px;
    }

    .el-main {
        background-color: #E9EEF3;
        color: #333;
        text-align: center;
        /*line-height: 160px;*/
    }

    body > .el-container {
        margin-bottom: 40px;
    }

    .el-container:nth-child(5) .el-aside,
    .el-container:nth-child(6) .el-aside {
        line-height: 260px;
    }

    .el-container:nth-child(7) .el-aside {
        line-height: 320px;
    }
</style>